package com.mobis.article.service;

import com.mobis.article.dao.ArticleDao;
import com.mobis.article.pojo.Article;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class ArticleService {

    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private ArticleDao articleDao;

    @Transactional
    public void examine(String id){
        articleDao.examine(id);
    }

    @Transactional
    public void addThumbup(String id){
        articleDao.addThumbup(id);
    }

    public Article findArticleById(String articleId) {

        //先从换从中获取
        Article article=(Article)redisTemplate.opsForValue().get("article_"+articleId);
        if (null==article){
            article= articleDao.findById(articleId).get();
            redisTemplate.opsForValue().set("article_"+articleId,article);
        }
      return  article ;
    }
}
